<template>
	<view>
		<navbar title='所在位置' :isBack="true
		"></navbar>
		<!-- <view class="item">
			不显示位置
		</view> -->
		<view class="content">
			<view class="item" v-for="(item,index) in regionList" @tap='selectRegion(index)'>
				<view class="" v-if="index == 0">
					不显示位置
				</view>
				<view v-if="index == 1">
					<view class="main">{{item.poiName}}</view>
					<view class="detail">{{item.province + item.city + item.district + item.street}}</view>
				</view>
				<view v-if="index > 1">
					<view class="main">{{item.address}}</view>
					<view class="detail">{{item.type}}</view>
				</view>
				<view class="outer" v-show="index === selectIndex">
					<view class="inner"></view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selectIndex: 0,
				regionList: ['不显示位置']
			};
		},
		onLoad() {
			this.getLocation()
		},
		methods: {
			selectRegion(index){
				this.selectIndex = index
				uni.navigateBack({
					delta:1
				})
				
				uni.$emit('chooseRegion',this.regionList[index],index)
			},
			getLocation() {
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					success: (res) => {
						this.getnearby(res.longitude,res.latitude)
						this.regionList.push(res.address)
					
					}
				});
			},
			//获取附近
			getnearby(longitude,latitude){
				uni.request({
					url:'https://restapi.amap.com/v3/place/around?parameters',
					data:{
					key:'7a94d71e18b4d07ac68caef2c961db5c',
					location:`${longitude},${latitude}`
					},
					method:'GET',
					success:res=>{
						console.log(res.data.pois)
						this.regionList = this.regionList.concat(res.data.pois)
							console.log(this.regionList)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item {
		// border-top: 1px solid rgba(128,128,128,.2);
		border-bottom: 1px solid rgba(128, 128, 128, .2);
		padding: 30rpx 25rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		min-height: 150rpx;
		font-size: 32rpx;
		.detail {
			font-size: 24rpx;
			color: rgba(128, 128, 128, .8);
		}
	}

	.content {
		// padding-top: 50rpx;
	}

	.outer {
		height: 30rpx;
		width: 30rpx;
		border-radius: 50%;
		border: 1px solid #007AFF;
		display: flex;
		justify-content: center;
		align-items: center;
		
		.inner {
			height: 14rpx;
			width: 14rpx;
			background-color: #007AFF;
			border-radius: 50%;

		}
	}
</style>
